package kr.hikt.androidcomplete01.ch07;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader.TileMode;
import android.os.Bundle;
import android.view.View;

public class LinearGrad extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new MyView(this));
	}

	class MyView extends View {
		private Paint pnt;
		private int[] colors = { Color.RED, Color.GREEN, Color.BLUE,
				Color.YELLOW, Color.WHITE };
		private float[] pos = { 0.0f, 0.1f, 0.6f, 0.9f, 1.0f };

		public MyView(Context context) {
			super(context);
			pnt = new Paint();
		}

		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);
			pnt.setAntiAlias(true);

			pnt.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE,
					Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(0, 0, 100, 100, pnt);
		
			pnt.setShader(new LinearGradient(110, 0, 210, 100, Color.BLUE,
					Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(110, 0, 210, 100, pnt);
			
			pnt.setShader(new LinearGradient(220, 100, 320, 0, Color.BLUE,
					Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(220, 0, 320, 100, pnt);
			
			pnt.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE,
					Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(0, 100, 320, 150, pnt);
			
			pnt.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE,
					Color.WHITE, TileMode.REPEAT));
			canvas.drawRect(0, 160, 320, 200, pnt);
			
			pnt.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE,
					Color.WHITE, TileMode.MIRROR));
			canvas.drawRect(0, 210, 320, 250, pnt);
			
			pnt.setShader(new LinearGradient(0, 0, 320, 0, colors,
					null, TileMode.CLAMP));
			canvas.drawRect(0, 260, 320, 300, pnt);
			
			pnt.setShader(new LinearGradient(0, 0, 320, 0,
					colors, pos, TileMode.CLAMP));
			canvas.drawRect(0, 310, 320, 350, pnt);
		}
	}
}
